<?php
namespace Home\Controller;
use Common\Controller\BaseController;

class UploadController extends BaseController{

	public function index(){
		$path = '/Public/Upload/' . date('Ymd') . '/';
		if(!file_exists($_SERVER["DOCUMENT_ROOT"] . $path)){
			mkdir($_SERVER["DOCUMENT_ROOT"] . $path, 0777, true);
			chmod($_SERVER["DOCUMENT_ROOT"] . $path, 0777);
		}
		$fileName = $path . date('His') . mt_rand(100, 999) . strrchr($_FILES['file']['name'], '.');
		move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . $fileName);
		exit('{"error":0, "url": "' . $fileName . '"}');
	}
}
?>